/**
 * 报警人
 * Aaron create by 2019/06/14
 */
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
} from 'typeorm';
import moment = require('moment');
import { Device } from './device.entity';

@Entity()
export class Caller {
  @PrimaryGeneratedColumn({
    comment: '自增ID',
  })
  id: number;

  @ManyToOne((type) => Device, (Device) => Device.caller)
  device: Device;

  @Column({
    type: 'int',
    nullable: true,
    comment: '设备id',
  })
  deviceId: number;

  @Column({
    nullable: true,
    comment: '接警人姓名',
    length: 20,
  })
  name: string;

  @Column({
    nullable: true,
    comment: '接警人电话',
    length: 20,
  })
  phone: string;

  @Column({
    nullable: true,
    comment: '允许接收电话',
    default: true,
  })
  isCall: boolean;

  @Column({
    nullable: true,
    comment: '允许接收短信',
    default: true,
  })
  isSms: boolean;

  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    comment: 'createAt',
    update: false,
    transformer: {
      to: (value) => {
        return value;
      },
      from: (value) => {
        return moment(value).format('YYYY-MM-DD HH:mm:ss');
      },
    },
  })
  creatTime: Date;

  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    comment: 'updateAt',
    update: true,
    transformer: {
      to: (value) => {
        return value;
      },
      from: (value) => {
        return moment(value).format('YYYY-MM-DD HH:mm:ss');
      },
    },
  })
  updateTime: Date;
}
